<html>
<head>
<?require './uahelp.php';?>
<?php 
$memcache = new Memcache();
$memcache->connect('localhost', '11211');
$control =  $_POST['param'];
$mobile = new mobile();
$ip = $mobile->getIP();
$ua = $mobile->getUA();
$phone_number = $mobile->getPhoneNumber();
$phone_type = $mobile->getPhoneType();
if($control == 'doLogic') {
	/**
	 * 做ip限制
	 */
	$ip_mem_count = $memcache->get($ip);
	if($ip_mem_count == 2) {
		echo '您已经提交两次: ' . $ip ;
		return;
	}
	if(!$ip_mem_count) {
		$memcache->set($ip, 1 ,0 ,0);
	}else {
		$ip_mem_count ++;
		$memcache->set($ip, $ip_mem_count ,0 ,0);
	}
	$typeValue = $_POST['typeValue'];
	$typeFlag = $memcache->get($typeValue);
	if(!$typeFlag) {
		$memcache->set($typeValue, 1, 0 , 0);
	} else {
		$typeFlag ++;
		$memcache->set($typeValue, $typeFlag, 0 , 0);
	}
	$typeFlag = $memcache->get($typeValue);
	$typeShow = '';
	if ($typeValue == 1) $typeShow = '吃饭+桌游';
	if ($typeValue == 2) $typeShow = '吃饭+杀人';
	if ($typeValue == 3) $typeShow = '吃饭+洗澡';
	if ($typeValue == 4) $typeShow = 'ktv带自助';
	$success = "您成功投了" . $typeShow . "，谢谢您的参与!";
//	echo $typeShow . ' : ' . $typeFlag . '票';
}
?>
<script type="text/javascript">
 	function doSubmit(count){
 	 	
		var formObj = document.getElementById('form1');
		var typeValue = document.getElementsByName('typeValue');
		var flag = false;
		var value = '';
		for(var i = 0; i < typeValue.length; i++){
			if(typeValue[i].checked){
					flag = true;
					value = typeValue[i].value
				} 
		}
		if(!flag){
			alert('请至少选择一项');
			return;
		}
		var show_1 = "";
		if (value == 1) show_1 = '吃饭+桌游';
		if (value == 2) show_1 = '吃饭+杀人';
		if (value == 3) show_1 = '吃饭+洗澡';
		if (value == 4) show_1 = 'ktv带自助';
		var sure = confirm('确定选择"' + show_1 + '"么?')
		
		if (count == 2) {
			alert('对不起您提交了两次了!');
			return;
 	 	}
		
		if (sure) {
			formObj.submit();
		} else {
			return;
		}
	 }

</script>
</head>
<body>

	<div style="height: 500px; width: 800px; border: 1px solid gray; margin-left: 200px; font-size: 12px;">
		<div style="text-align: center; margin-top: 50px;">
			<form id="form1" action="vote.php" method="post">
				<input name="param" value="doLogic" type="hidden" />
				<input name="typeValue" value="1" type="radio" <?= $typeValue == '1' ? 'checked' : ''?>/>吃饭+桌游
				<input name="typeValue" value="2" type="radio" <?= $typeValue == '2' ? 'checked' : ''?>/>吃饭+杀人
				<input name="typeValue" value="3" type="radio" <?= $typeValue == '3' ? 'checked' : ''?>/>吃饭+洗澡
				<input name="typeValue" value="4" type="radio" <?= $typeValue == '4' ? 'checked' : ''?>/>ktv带自助
				<div></div>
				<input name="sumbit" type="button"" value="提交" onclick="doSubmit('<?=$memcache->get($ip) ?>')" />
				<div style="color: blue">
				个人信息如下：(每人两次选择，请勿尝试多次提交)
				</div>
				<div>
				IP:<? 
				
				echo $ip;
				?>
				</div>
				<div>
				UA:
				<?php 
					echo $ua;
				?>
				</div>
				<div>
				 <?php 
				 	
				 	if ($phone_number) {
					 	echo '手机号码：' . $phone_number;
				 	} else {
				 		echo 'PC端访问<br/>' ;
				 	}
				 	if ($phone_type) echo   '手机型号/浏览器版本：' . $phone_type;
				 ?>
				</div>
				
			</form>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
if ('<?=$success?>' != '' &&  '<?=$success?>' != null) {

   alert('<?=$success?>');
	
}
</script>




